<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.bson.Document" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page import="com.mongodb.client.result.DeleteResult" %>
<%@ page import="java.util.Arrays" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String url = "mongodb://g08:abc%408@mongo.zhledu.cn:27017/g08";
    MongoClient client = MongoClients.create(url);
    MongoIterable<String> names = client.listDatabaseNames();
    MongoDatabase g08 = client.getDatabase("g08");
    MongoCollection<Document> collection = g08.getCollection("student");
    String sno = request.getParameter("sno");
    String[] snos = sno.split(",");
    Document query = new Document("sno", new Document("$in", Arrays.asList(snos)));
    DeleteResult result = collection.deleteMany(query);
    response.setCharacterEncoding("utf-8");
    if (result.getDeletedCount() > 0) {
        response.getWriter().write("<script language=JavaScript>{window.alert('删除成功,共删除" + result.getDeletedCount() + "条记录!');window.location.href='index.jsp'}</script>");

    } else {
        response.getWriter().write("<script language=JavaScript>{window.alert('删除失败!');window.location.href='index.jsp'}</script>");
    }
%>